package com.lmk.service.impl;

import com.lmk.domain.Product;
import com.lmk.domain.Store;
import com.lmk.dto.ProductDto;
import com.lmk.feign.StoreService;
import com.lmk.mapper.ProductMapper;
import com.lmk.service.ProductService;
import com.lmk.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private StoreService storeService;
    @Override
    public AjaxResult add(ProductDto productDto) {
        Product product = new Product();
        product.setName(productDto.getName());
        product.setPrice(productDto.getPrice());
        productMapper.add(product);

        Store store = new Store();
        store.setProduct_id(product.getId());
        store.setNumber(productDto.getNumber());
        AjaxResult result = storeService.add(store);
        //如果返回状态为false就删掉
       /* if (result.getSuccess() == false){
            productMapper.del(product.getId());
        }*/
        return result;
    }
}
